﻿import math
import numpy as np

# # arr = np.array([8.8, 9.2, 11])
# arr = np.array([0,0,0,0,1,1])
# #arr = np.array([0,0,0,0,0,1,1,1,1,1])
# # arr = np.array([7.2, 9.2,  8.4, 7.6,  10.2])

# # 计算均值
# mean = np.mean(arr)
# print("均值:", mean)

# # 计算方差
# variance = np.var(arr)


# probabilities = [3 / 8, 5 / 8]

# # 计算信息熵
# entropy = -sum(p * math.log2(p) for p in probabilities)

# print(f"信息熵 H(X): {entropy} 比特")

import matplotlib.pyplot as plt


# # 定义函数
# def f(x):
#     # 使用numpy的where函数来处理x=0和x=1的情况
#     # return np.where((x == 0) | (x == 1), 0, -x * np.log2(x) - (1 - x) * np.log2(1 - x))
#     return np.where((x == 0) | (x == 1), 0, 1 - (x**2) - ((1 - x) * (1 - x)))


# # 创建x值的列表
# x = np.linspace(0, 1, 500)

# # 计算对应的y值
# y = f(x)

# # 创建图形
# plt.figure(figsize=(8, 6))
# plt.plot(x, y, label=r"$f(x) = -x \log_2 x - (1-x) \log_2 (1-x)$")
# plt.title("Plot of the function $f(x) = -x \log_2 x - (1-x) \log_2 (1-x)$")
# plt.xlabel("x")
# plt.ylabel("f(x)")
# plt.grid(True)
# plt.legend()
# plt.show()

xxx = np.sin(0.5 * math.pi) - (
    4 / 10 * np.sin(3 * math.pi / 4) + 6 / 10 * np.sin(1 * math.pi / 3)
)
print(xxx)